/*
This file is part of Docking@Home.
http://docking.gcl.cis.udel.edu
Copyright (C) 2009 University of Delaware

Docking@Home is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Docking@Home is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Docking@Home.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Filename: GLHelper.h
	Description: A public class of openGL functions that are commonly used
		in this application so that one does not have to rewrite them at any
		given point.
	Revision History: 
		Created - 01/02/08
	Author: Robert Keller
*/

#ifndef _GLHelper_h
#define _GLHelper_h

#include "parse.h"
#include "texfont.h"
#include "./Math/MathHelper.h"

#include <vector>

using std::vector;

class GLHelper
{
public:

	// Constructor / Destructor
	GLHelper();
	~GLHelper();

	// Render Mode Functions (Orhtographic, Perspective)

	static void setOrthographic ();
	static void setOrthographicDone ();

	// Viewport Functions

	static void setViewport(int x, int y, int x2, int y2);
	static void setViewportProperties (double dist);

	static int getViewportWidth ();
	static int getViewportHeight ();

	// Camera Functions

	static void initCamera (double fov, double aspectRatio,
		double nearClip, double farClip);

	// Lighting Functions

	static void initLights (float amb[4], float pos[4], float dir[4]);

	// Rectangle Drawing Functions

	static void drawRect (float x1, float y1, float x2, 
		float y2, const float color[4]);
	static void drawRectWH (float x1, float y1, float width, 
		float height, const float color[4]);
	static void drawFilledRectWH (float x1, float y1, float width,
		float height, const float color[4]);

	// Line Drawing Functions

	static void drawLine (float pos1[3], float pos2[3], 
		const float color[4]);
	static void drawLine (float x1, float y1, 
		float x2, float y2, const float color[4]);
	static void drawLine (float x1, float y1, float z1, 
		float x2, float y2, float z2, const float color[4]);

	// Quadrilateral Drawing Functions

	static void drawQuad (float x1, float y1, float x2, 
		float y2, const float color[4]);
	static void drawQuadWH (float x1, float y1, float width, 
		float height, const float color[4]);
	static void drawTexturedQuad (float x1, float y1, float x2, 
		float y2, const float color[4], unsigned int texID);
	static void drawTexturedQuadWH (float x1, float y1, float width, 
		float height, const float color[4], unsigned int texID);

	// Cylinder Drawing Functions

	static void drawCylinder(float x, float y, float z, float len, 
		float radius, int angle, float rotAxis[3]);

	static void drawCylinder(float pos[3], float len, 
		float radius, int angle, float rotAxis[3]);

	// Graph Drawing Functions

	static void drawAxis(float &x, float &y, float &width, 
		float &height, float &xMin, float &yMin, float &xMax, 
		float &yMax, float textXScale, float textYScale, 
		const float axisColor[4], bool bTicks);

	static void drawLineGraph (float x, float y, float width, 
		float height, float xMin, float yMin, float xMax, 
		float yMax, float textXScale, float textYScale, 
		vector<Point2fT> points, const float axisColor[4],
		bool bTicks);

	// Text Functions

	static bool fontsLoaded ();

	static void loadFonts(const char * dir);
	static void loadDefaultFonts();

	static void drawText(float alphaValue, double x, double y, 
		double z, float xscale, float yscale, float zscale,
		const float color[4], int fontIndex, char * string);

	static void getDrawnTextProperties (char * str, int fontIndex, 
		int * width, int * max_ascent, int * max_descent);

	// Color Functions

	static void getColorFromID (float color[4], int id);

	// Color Copy Functions

	static void copyColor4f (float dest[4], const float src[4]);

	// Static Color Constants
	static const float WHITE[4];
	static const float CYAN[4];	
	static const float BLUE[4];
	static const float RED[4];
	static const float YELLOW[4];
	static const float ORANGE[4];
	static const float GRAY[4];
	static const float TAN[4];
	static const float SILVER[4];
	static const float BLACK[4];

	// Text Shifting Constants
	static const float AVERAGE_TEXT_SHIFT_RIGHT;
	static const float AVERAGE_TEXT_SHIFT_UP;

	// Cleanup
	static void cleanup ();

private:

	// Texture Fonts

	static TexFont* texFonts [TXF_NUM_FONT];

	static const char * DEFAULT_TEXFONT_PATH;	
};

#endif
